﻿using System;
using System.Windows.Forms;

namespace Ry.Error
{
    public partial class RyError : Form
    {
        public RyError()
        {
            InitializeComponent();
        }

        public DialogResult ShowError(Exception e, System.Diagnostics.StackFrame frame)
        {
            this.Text = "系统错误";

            System.Reflection.MethodBase mb = frame.GetMethod();
            edtInfo.Text = e.Message;
            edtContext.Text = mb.ToString();
            edtPos.Text = string.Format("类名：{0}   方法名:{1}    行号:{2}", mb.DeclaringType.Name, mb.Name, frame.GetFileLineNumber());
            btnCancel.Visible = false;
            btnRetry.Visible = false;
            return ShowDialog();
        }

        public DialogResult ShowError(Exception e,string info, System.Diagnostics.StackFrame frame)
        {
            this.Text = "系统错误";

            System.Reflection.MethodBase mb = frame.GetMethod();
            edtInfo.Text = e.Message;
            edtContext.Text = mb.ToString() + "\n--------------------------\n" + info;
            edtPos.Text = string.Format("类名：{0}   方法名:{1}    行号:{2}", mb.DeclaringType.Name, mb.Name, frame.GetFileLineNumber());
            btnCancel.Visible = false;
            btnRetry.Visible = false;
            return ShowDialog();
        }


        public DialogResult ShowMyError(string info,string pos,string context)
        {
            this.Text = "自定义错误";
            edtInfo.Text = info;
            edtContext.Text = pos;
            edtPos.Text = context;
            btnCancel.Visible = false;
            btnRetry.Visible = false;
            return ShowDialog();
        }

        public DialogResult ShowMyWarning(string info, string pos, string context)
        {
            this.Text = "警告";
            edtInfo.Text = info;
            edtContext.Text = pos;
            edtPos.Text = context;
            btnCancel.Visible = false;
            btnRetry.Visible = false;
            return ShowDialog();
        }

        public DialogResult ShowMyHint(string info, string pos, string context)
        {
            this.Text = "提示信息";
            edtInfo.Text = info;
            edtContext.Text = pos;
            edtPos.Text = context;
            btnCancel.Visible = false;
            btnRetry.Visible = false;
            return ShowDialog();
        }

        public DialogResult ShowOkCancel(string info, string pos, string context)
        {
            this.Text = "提示信息";
            edtInfo.Text = info;
            edtContext.Text = pos;
            edtPos.Text = context;
            btnCancel.Visible = true;
            btnRetry.Visible = false;
            return ShowDialog();
        }

        public DialogResult ShowOkCancelRetry(string info, string pos, string context)
        {
            this.Text = "提示信息";
            edtInfo.Text = info;
            edtContext.Text = pos;
            edtPos.Text = context;
            btnCancel.Visible = true;
            btnRetry.Visible = true;
            return ShowDialog();
        }
    }
}
